
package com.xin.di.uav.applet.mapper;

import com.xin.di.uav.common.response.IdAndNameResp;
import com.xin.di.uav.operate.po.ServiceAreaPO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ServiceAreaMapper {
    @Insert({"<script>",
            "INSERT INTO scenic_spot (id, name, latitude, longitude, address, ",
            "contacts, phone,  status)",
            "VALUES (#{id}, #{name}, #{latitude}, #{longitude}, #{address}, ",
            "#{contacts}, #{phone},  #{status})",
            "</script>"})
    int insert(ServiceAreaPO serviceArea);

    int deleteById(String id);

    // 动态字段更新（只更新非空字段）
    @Update({
            "<script>",
            "UPDATE scenic_spot ",
            "<set>",
            "    <if test='name != null'>name = #{name},</if>",
            "    <if test='latitude != null'>latitude = #{latitude},</if>",
            "    <if test='longitude != null'>longitude = #{longitude},</if>",
            "    <if test='address != null'>address = #{address},</if>",
            "    <if test='contacts != null'>contacts = #{contacts},</if>",
            "    <if test='phone != null'>phone = #{phone},</if>",
            "    <if test='status != null'>status = #{status},</if>",
            "    update_time = NOW()",

            "</set>",
            "WHERE id = #{id}",
            "</script>"
    })
    int updateById(ServiceAreaPO serviceArea);

    @Select({"<script>",
            "select id, name, latitude, longitude, address, contacts, phone,\n" +
                    "                           create_time, update_time, status\n" +
                    "from scenic_spot where id =#{id} ",
            "</script>"})
    ServiceAreaPO selectById(String id);


    @Select({"<script>",
            "select id, name as name \n" +
                    "from scenic_spot where id in ",
            "       <foreach item=\"id\" collection=\"ids\" open=\"(\" separator=\",\" close=\")\">\n" +
                    "            #{id}\n" +
                    "        </foreach>" +
                    "</script>"})
    List<IdAndNameResp> selectIdAndName(@Param("ids") List<String> ids);

    @Select({"<script>",
            "select count(1) \n" +
                    "from scenic_spot where 1=1  ",
            "    <if test='serviceRegion != null and serviceRegion !=\"\"  '> and  name like CONCAT('%', #{serviceRegion}, '%') </if>",
            "</script>"})
    int count(String serviceRegion);


    @Select({"<script>",
            "select id, name, latitude, longitude, address, contacts, phone,\n" +
                    "                           create_time, update_time, status\n" +
                    " from scenic_spot where  1=1 " +
                    "    <if test='serviceRegion != null and serviceRegion !=\"\"  '> and  name like CONCAT('%', #{serviceRegion}, '%') </if>",
            "order by create_time desc   limit #{offset},#{pageSize} ",
            "</script>"})
    List<ServiceAreaPO> selectList(@Param("serviceRegion") String serviceRegion, @Param("offset") int offset, @Param("pageSize") int pageSize);

    @Select({"<script>",
            "select id,name as name \n" +
                    " from scenic_spot where  1=1 " +
                    "    <if test='serviceRegion != null and serviceRegion !=\"\"  '> and  name like CONCAT('%', #{serviceRegion}, '%') </if>",
            "order by create_time desc   ",
            "</script>"})
    List<IdAndNameResp> searchList(String serviceRegion);
}
